home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / starwars.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  6KB  |  225 lines

  1. /***************************************************************************
  2. sndhrdw\starwars.c
  3.  
  4. STARWARS MACHINE FILE
  5.  
  6. This file created by Frank Palazzolo. (palazzol@home.com)
  7.  
  8. Release 2.0 (6 August 1997)
  9.  
  10. See drivers\starwars.c for notes
  11.  
  12. ***************************************************************************/
  13.  
  14. #include "driver.h"
  15. #include "cpu/m6809/m6809.h"
  16.  
  17. /* Sound commands from the main CPU are stored in a single byte */
  18. /* register.  The main CPU then interrupts the Sound CPU.       */
  19.  
  20. static int port_A = 0;   /* 6532 port A data register */
  21.  
  22.                          /* Configured as follows:           */
  23.                          /* d7 (in)  Main Ready Flag         */
  24.                          /* d6 (in)  Sound Ready Flag        */
  25.                          /* d5 (out) Mute Speech             */
  26.                          /* d4 (in)  Not Sound Self Test     */
  27.                          /* d3 (out) Hold Main CPU in Reset? */
  28.                          /*          + enable delay circuit? */
  29.                          /* d2 (in)  TMS5220 Not Ready       */
  30.                          /* d1 (out) TMS5220 Not Read        */
  31.                          /* d0 (out) TMS5220 Not Write       */
  32.  
  33. static int port_B = 0;     /* 6532 port B data register        */
  34.                            /* (interfaces to TMS5220 data bus) */
  35.  
  36. static int irq_flag = 0;   /* 6532 interrupt flag register */
  37.  
  38. static int port_A_ddr = 0; /* 6532 Data Direction Register A */
  39. static int port_B_ddr = 0; /* 6532 Data Direction Register B */
  40.                            /* for each bit, 0 = input, 1 = output */
  41.  
  42. static int PA7_irq = 0;  /* IRQ-on-write flag (sound CPU) */
  43.  
  44. /********************************************************/
  45.  
  46. static void snd_interrupt(int foo)
  47. {
  48.     irq_flag |= 0x80; /* set timer interrupt flag */
  49.     cpu_cause_interrupt (1, M6809_INT_IRQ);
  50. }
  51.  
  52. /********************************************************/
  53.  
  54. READ_HANDLER( starwars_m6532_r )
  55. {
  56.     static int temp;
  57.  
  58.     switch (offset)
  59.     {
  60.         case 0: /* 0x80 - Read Port A */
  61.  
  62.             /* Note: bit 4 is always set to avoid sound self test */
  63.  
  64.             return port_A|0x10|(!tms5220_ready_r()<<2);
  65.  
  66.         case 1: /* 0x81 - Read Port A DDR */
  67.             return port_A_ddr;
  68.  
  69.         case 2: /* 0x82 - Read Port B */
  70.             return port_B;  /* speech data read? */
  71.  
  72.         case 3: /* 0x83 - Read Port B DDR */
  73.             return port_B_ddr;
  74.  
  75.         case 5: /* 0x85 - Read Interrupt Flag Register */
  76.             temp = irq_flag;
  77.             irq_flag = 0;   /* Clear int flags */
  78.             return temp;
  79.  
  80.         default:
  81.             return 0;
  82.     }
  83.  
  84.     return 0; /* will never execute this */
  85. }
  86. /********************************************************/
  87.  
  88. WRITE_HANDLER( starwars_m6532_w )
  89. {
  90.     switch (offset)
  91.     {
  92.         case 0: /* 0x80 - Port A Write */
  93.  
  94.             /* Write to speech chip on PA0 falling edge */
  95.  
  96.             if((port_A&0x01)==1)
  97.             {
  98.                 port_A = (port_A&(~port_A_ddr))|(data&port_A_ddr);
  99.                 if ((port_A&0x01)==0)
  100.                     tms5220_data_w(0,port_B);
  101.             }
  102.             else
  103.                 port_A = (port_A&(~port_A_ddr))|(data&port_A_ddr);
  104.  
  105.             return;
  106.  
  107.         case 1: /* 0x81 - Port A DDR Write */
  108.             port_A_ddr = data;
  109.             return;
  110.  
  111.         case 2: /* 0x82 - Port B Write */
  112.             /* TMS5220 Speech Data on port B */
  113.  
  114.             /* ignore DDR for now */
  115.             port_B = data;
  116.  
  117.             return;
  118.  
  119.         case 3: /* 0x83 - Port B DDR Write */
  120.             port_B_ddr = data;
  121.             return;
  122.  
  123.         case 7: /* 0x87 - Enable Interrupt on PA7 Transitions */
  124.  
  125.             /* This feature is emulated now.  When the Main CPU  */
  126.             /* writes to mainwrite, it may send an IRQ to the    */
  127.             /* sound CPU, depending on the state of this flag.   */
  128.  
  129.             PA7_irq = data;
  130.             return;
  131.  
  132.  
  133.         case 0x1f: /* 0x9f - Set Timer to decrement every n*1024 clocks, */
  134.             /*        With IRQ enabled on countdown               */
  135.  
  136.             /* Should be decrementing every data*1024 6532 clock cycles */
  137.             /* 6532 runs at 1.5 Mhz, so there a 3 cylces in 2 usec */
  138.  
  139.             timer_set (TIME_IN_USEC((1024*2/3)*data), 0, snd_interrupt);
  140.             return;
  141.  
  142.         default:
  143.             return;
  144.     }
  145.  
  146.     return; /* will never execute this */
  147.  
  148. }
  149.  
  150. static int sound_data;    /* data for the sound cpu */
  151. static int main_data;   /* data for the main  cpu */
  152.  
  153. /********************************************************/
  154. /* These routines are called by the Sound CPU to        */
  155. /* communicate with the Main CPU                        */
  156. /********************************************************/
  157.  
  158. READ_HANDLER( starwars_sin_r )
  159. {
  160.     int res;
  161.  
  162.     port_A &= 0x7f; /* ready to receive new commands from main */
  163.     res = sound_data;
  164.     sound_data = 0;
  165.     return res;
  166. }
  167.  
  168. WRITE_HANDLER( starwars_sout_w )
  169. {
  170.     port_A |= 0x40; /* result from sound cpu pending */
  171.     main_data = data;
  172.     return;
  173. }
  174.  
  175. /********************************************************/
  176. /* The following routines are called from the Main CPU, */
  177. /* not the Sound CPU.                                   */
  178. /* They are here because they are all related to sound  */
  179. /* CPU communications                                   */
  180. /********************************************************/
  181.  
  182. READ_HANDLER( starwars_main_read_r )
  183. {
  184.     int res;
  185.  
  186.     logerror("main_read_r\n");
  187.  
  188.     port_A &= 0xbf;  /* ready to receive new commands from sound cpu */
  189.     res = main_data;
  190.     main_data = 0;
  191.     return res;
  192. }
  193.  
  194. /********************************************************/
  195.  
  196. READ_HANDLER( starwars_main_ready_flag_r )
  197. {
  198. #if 0 /* correct, but doesn't work */
  199.     return (port_A & 0xc0); /* only upper two flag bits mapped */
  200. #else
  201.     return (port_A & 0x40); /* sound cpu always ready */
  202. #endif
  203. }
  204.  
  205. /********************************************************/
  206.  
  207. WRITE_HANDLER( starwars_main_wr_w )
  208. {
  209.     port_A |= 0x80;  /* command from main cpu pending */
  210.     sound_data = data;
  211.     if (PA7_irq)
  212.         cpu_cause_interrupt (1, M6809_INT_IRQ);
  213. }
  214.  
  215. /********************************************************/
  216.  
  217. WRITE_HANDLER( starwars_soundrst_w )
  218. {
  219.     port_A &= 0x3f;
  220.  
  221.     /* reset sound CPU here  */
  222.     cpu_set_reset_line(1,PULSE_LINE);
  223. }
  224.  
  225.